package sk.klimo.prototyp.client;

import sk.klimo.prototyp.client.event.HasUpdateItemEvents;
import sk.klimo.prototyp.client.event.UpdateItemEvent;
import sk.klimo.prototyp.client.event.UpdateItemEventHandler;
import sk.klimo.prototyp.client.model.InvoiceItem;

import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;

public class InvoiceItemsTable extends FlexTable implements HasUpdateItemEvents {

	public InvoiceItemsTable() {
		super();

		// this.setBorderWidth(1);
		// this.setText(0, 0, "upper-left corner");
		// this.setText(2, 2, "bottom-right corner");
		// this.setWidget(1, 0, new Button("Wide Button"));
	}

	public HandlerRegistration addUpdateItemHandler(
			UpdateItemEventHandler handler) {
		return this.addHandler(handler, UpdateItemEvent.TYPE);
	}

	public void addRow(InvoiceItem item) {
		int row = this.getDOMRowCount() + 1;
		this.setWidget(row, 0, new CheckBox());
		this.setWidget(row, 1, new Label(item.getNazov()));
		this.setWidget(row, 2, new Label(item.getJednotkovaCena()));
		this.setWidget(row, 3, new Label(item.getPocet()));
		this.setWidget(row, 4, new Button("Delete"));
	}
}
